/**
 * This file is released under the GNU General Public License.
 * Refer to the COPYING file distributed with this package.
 *
 * Copyright (c) 2008-2009 WURFL-Pro srl
 */
package net.sourceforge.wurfl.core.handlers;

import net.sourceforge.wurfl.core.request.normalizer.UserAgentNormalizer;

import org.apache.commons.lang.StringUtils;

/**
 * User-agent handler.
 * 
 * <p>
 * Used by matchers and classifiers to intercept the devices. 
 * </p>
 * 
 * @author WURFL-PRO SRL, Rome, Italy
 * @version $Id: Handler.java 1045 2009-03-09 15:52:53Z filippo.deluca $
 */
public abstract class Handler {
	
	private static final String[] mobileBrowsers = new String[]{"Tablet", "Mobile", "Wireless", "Palm", "Blazer", "NetFront", "Symbian", "Bolt", "Iris"};
	
	private UserAgentNormalizer normalizer;
	
	public Handler(UserAgentNormalizer normalizer) {
		this.normalizer = normalizer;
	}

	/**
	 * Test if this Handler handles the given user-agent.
	 * 
	 * @param userAgent
	 *            The user-agent to probe.
	 * @return True if this user-agent can be handled, false otherwise.
	 */
	public abstract boolean canHandle(String userAgent);
	
	public String normalize(String userAgent) {
		return normalizer.normalize(userAgent);
	}
	
	
	/**
	 * 
	 * @param userAgent
	 * @return
	 */
	public boolean isMobileBrowser(String userAgent) {
		boolean isMobile = false;
		for (int i=0;i<mobileBrowsers.length;i++) {
			if(StringUtils.containsIgnoreCase(userAgent, mobileBrowsers[i])) {
				isMobile = true;
				break;
			}
		}
		return isMobile;
		
	}
	
}
